package ${package.Controller};

<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>
import ${cfg.commonPackge}.PageParams;
import ${cfg.commonPackge}.PageResult;
import ${cfg.commonPackge}.AppResp;
import ${cfg.voEntityPackage}.${entity}VO;
import ${package.Service}.${entity}Service;
<#if swagger2>
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
</#if>
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * <#if (table.comment)?trim?length gt 1>${table.comment}<#else>${entity}</#if> 控制层
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
<#if swagger2>
@Api(tags = "<#if (table.comment)?trim?length gt 1>${table.comment}<#else>${entity}</#if>相关接口")
</#if>
@Validated
@RestController("${'${table.controllerName}'?uncap_first}4${cfg.module}")
@RequestMapping("${cfg.requestMappingUrlPrefix}/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>

    @Autowired
    private ${table.serviceName} ${'${entity}Service'?uncap_first};

    <#if swagger2>
    @ApiOperation(value = "查询列表分页")
    </#if>
    @PostMapping("/page")
    public AppResp<PageResult<${entity}VO>> page(@RequestBody PageParams<${entity}VO> pageParams){
        return ${'${entity}Service'?uncap_first}.page(pageParams);
    }

    <#if swagger2>
    @ApiOperation(value = "根据记录Id查询")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "${'${entity}'?uncap_first}Id", value = "记录id", required = true)
    })
    </#if>
    @GetMapping("")
    public AppResp<${entity}VO> queryById(@RequestParam Long ${'${entity}'?uncap_first}Id){
        return ${'${entity}Service'?uncap_first}.queryById(${'${entity}'?uncap_first}Id);
    }

    <#if swagger2>
    @ApiOperation(value = "添加记录")
    </#if>
    @PostMapping("")
    public AppResp<Void> add(@Validated ${entity}VO ${'${entity}'?uncap_first}VO){
        return ${'${entity}Service'?uncap_first}.add(${'${entity}'?uncap_first}VO);
    }

    <#if swagger2>
    @ApiOperation(value = "删除记录")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "${'${entity}'?uncap_first}Id", value = "记录id", required = true)
    })
    </#if>
    @DeleteMapping("")
    public AppResp<Void> delById(@RequestParam Long ${'${entity}'?uncap_first}Id){
        return ${'${entity}Service'?uncap_first}.delById(${'${entity}'?uncap_first}Id);
    }

    <#if swagger2>
    @ApiOperation(value = "修改记录")
    </#if>
    @PutMapping("")
    public AppResp<Void> modify(@Validated ${entity}VO ${'${entity}'?uncap_first}VO){
        return ${'${entity}Service'?uncap_first}.modify(${'${entity}'?uncap_first}VO);
    }
}